package com.etiya.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import com.etiya.baglanti.EntityUtil;
import com.etiya.entity.Dil;
@SuppressWarnings("unchecked")
public class DilKayitBean implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6032009603914713360L;
	
	public DilKayitBean() {
	 
		dilListesi();
	}
	

	private Dil dil = new Dil();
	
	private List<Dil> dilListeleri = new ArrayList<Dil>();
    
	

	
	public void setDil(Dil dil) {
		this.dil = dil;
	}

	public Dil getDil() {
		return dil;
	}

	public String kayit() {
		
		EntityManager em = EntityUtil.getEntityManager();
		
		try{
		
		if (!em.getTransaction().isActive()) {
			
			em.getTransaction().begin();
			
			em.persist(dil);
			
			em.getTransaction().commit();
			
			dil= new Dil();
			
			dilListesi();
			
		}
		
		}catch(Exception e){
		 	
			em.flush();
		}
		return null;

	}
	
	public String sil() {
		
		EntityManager em = EntityUtil.getEntityManager();
		
	try{	
     if (!em.getTransaction().isActive()) {
					
		em.getTransaction().begin();		
		em.remove(dil);	
		em.getTransaction().commit();	
		dil = new Dil();
		
		dilListesi();
		}
	}catch (Exception e) {
	  
		em.flush();
	}
     
		return null;

	}
	public String duzenle() {
		
		EntityManager em = EntityUtil.getEntityManager();
		
	try{
		
		if (!em.getTransaction().isActive()) {
			
			em.getTransaction().begin();
			em.merge(dil);
			em.getTransaction().commit();
			dil = new  Dil();
			
			dilListesi();
		}
		
	}catch(Exception e){
		
		em.flush();
	}
   
		return null;
	}
	
	public String yeni() {
		
		dil = new Dil();

		 return null;
	}
   

	public List<Dil> dilListesi(){
		
		EntityManager em = EntityUtil.getEntityManager();
		
		setDilListeleri(em.createQuery("from Dil").getResultList());
		
		return null;
	}

	public void setDilListeleri(List<Dil> dilListeleri) {
		this.dilListeleri = dilListeleri;
	}

	public List<Dil> getDilListeleri() {
		return dilListeleri;
	}


}
